/**
 * Created by yangfan on 2016/10/25.
 */
define([
    'config/appregister',
    "i18n",
    "business/personMine/services/httpServices",
    "business/personMine/services/mineDirective",
    "business/services/personCenterComp",
    "business/services/detailNavComp",
    "business/services/filter"
],function(app,i18n,httpService){
    app.controller('othersMainPageCtrl', function($scope,$state,$stateParams,$rootScope) {
        $scope.i18n = i18n;
        $scope.goToBlog = function(state){
            if(!state){
                return
            }
            $state.go(state,{userId:$stateParams.userId});
        };
        $scope.listParams = {
            pageNo:1,
            pageSize:10,
            totalItem:"",
        };
        if( !angular.isUndefined($stateParams.userId)){
            $scope.userId = $stateParams.userId;
        }
        getBasePersonInfoByOther();
        function getBasePersonInfoByOther(){
            var req = {
                type:"GET",
                uri:"getBasePersonInfoByOther",
                data:{
                    otherUserId:$stateParams.userId
                }
            };
            httpService.personServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.userPic = response.data.logo ;
                })
            }).error(function(){})
        }

        function getPersonDynamicList(){
            var req = {
                type:"GET",
                uri:"getPersonDynamicList",
                data:{
                    userId:$stateParams.userId,
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize,
                    time:true

                }
            };
            httpService.myEngServices(req).success(function(response){
                $scope.$apply(function(){
                    if($scope.listParams.pageNo ==1){
                        $scope.personList = response.data.list;
                    }else{
                        $scope.personList = $scope.personList.concat(response.data.list);
                    }
                    $scope.totalItem = response.data.Pagination.totalCount;
                });
            }).error(function(){

            })
        }
        function getFollowList(){
            var req = {
                type:"GET",
                uri:"getOtherFollowList",
                //最多只查看6个
                data:{
                    pageNo:1,
                    pageSize:6,
                    userId: $stateParams.userId
                }

            };
            httpService.followServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.follows = response.data.list;
                });
            }).error(function(){

            })
        }
        getPersonDynamicList();
        getFollowList();

        $scope.loadMoreComment = function(){
            $scope.listParams.pageNo++;
            getPersonDynamicList();
        }


        //获取Ta的问答
        function getPostbarById(){
            var req = {
                type:"GET",
                uri:"getReplyByUserId",
                data:{
                    pageNo:1,
                    pageSize:6,
                    userId: $stateParams.userId
                }
            };
            httpService.postbarServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.postbar = response.data.list;
                });
            }).error(function(){

            })
        }
        getPostbarById();

        //获取我的视频
        function getMyCourse(){
            var req = {
                type:"GET",
                uri:"getHeCourse",
                data:{
                    userId:$stateParams.userId,
                    pageNo:'1',
                    pageSize:'10',
                    all:'false'
                }
            };
            httpService.videoServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.video = response.data.list;
                });
            }).error(function(){

            })
        }
        getMyCourse();

        //获取Ta的上传
        function myUploadFile(){
            var req = {
                type:"GET",
                uri:"uploadFileByUserId",
                data:{
                    pageNo:1,
                    pageSize:10,
                    userId:$scope.userId
                }
            };
            httpService.fileServices(req).success(function(response){
                $scope.$apply(function(){
                    console.log(response)
                    $scope.fileList = response.data.list;
                });
            }).error(function(){

            })
        }
        myUploadFile();

        //更多  --  跳转
        $scope.goMore = function(state){
            $state.go(state,{userId:$scope.userId,type:'care'})
        };

        //跳转详情
        $scope.goDetail = function(type,id){
            if(type == 'file'){
                $state.go('eng.techdetail',{fileId:id})
            }else if(type == 'course'){
                $state.go('eng.vedioDetails',{courseId:id})
            }else if(type == 'postbar'){
                $state.go('eng.postbardeta',{postbarId:id})
            }
        }
        $scope.jumpToPage = function(item){
            if(item.userType == 1){
                $state.go('othersMainPage',{userId:item.userId})
            }else{
                $state.go('outIndexCtrl',{companyId:item.followUserId})
            }

        }
    })
});
